package ua.ck.example.util;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class TimeUtil {
	private Calendar calendar = null;

	public TimeUtil() {
		this.calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+8"));
		this.calendar.set(11, 0);
		this.calendar.set(12, 0);
		this.calendar.set(13, 0);
		this.calendar.set(14, 0);
	}

	public TimeUtil(Timestamp currentTime) {
		if (currentTime != null) {
			this.calendar = Calendar.getInstance();
			this.calendar.setTimeInMillis(currentTime.getTime());
		} else {
			this.calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+8"));
		}
		this.calendar.set(11, 0);
		this.calendar.set(12, 0);
		this.calendar.set(13, 0);
		this.calendar.set(14, 0);
	}

	public Timestamp getToday() {
		return new Timestamp(this.calendar.getTimeInMillis());
	}

	public Timestamp getTime(int hours) {
		return new Timestamp(this.calendar.getTimeInMillis() + hours * 3600000L);
	}

	public static Timestamp getCurrent() {
		return new Timestamp(new GregorianCalendar(
				TimeZone.getTimeZone("GMT+8")).getTimeInMillis());
	}

	public Timestamp getTimeBeforeCurrent(int hours) {
		return new Timestamp(new GregorianCalendar(
				TimeZone.getTimeZone("GMT+8")).getTimeInMillis()
				- hours * 3600000L);
	}

	public Timestamp getTimestamp(int days) {
		Timestamp timestamp = new Timestamp(this.calendar.getTimeInMillis()
				- 86400000L * days);
		return timestamp;
	}

}